
<?php
/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 */

$baseURL = "{$_SERVER['PHP_SELF']}?newscode={$_GET['newscode']}";
$action = $_GET['action'];

if ($action == 'ViewAdd') {
	$new = true;
	$btnAction="addSave()";
	$heading = $lang_News_Add_Heading;
	$formAction = "{$baseURL}&action=Add";
	$disabled = '';
	
} else {
	$new = false;
	$btnAction="addUpdate()";
	$heading = $lang_News_Edit_Heading;
	$formAction = "{$baseURL}&action=Update";
	$disabled = "disabled='true'";

}

$locRights=$_SESSION['localRights'];

?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../../scripts/archive.js"></script>
<script type="text/javascript" src="../../scripts/octopus.js"></script>
<script>
	var editMode = <?php echo $new ? 'true' : 'false'; ?>;

	var employeeSearchList = new Array();
	
    function goBack() {
        location.href = "<?php echo $baseURL; ?>&action=List";
    }

	function validate() {
	
		err = false;
		msg = '<?php echo $lang_Error_PleaseCorrectTheFollowing; ?>\n\n';
	/*
		errors = new Array();
        if ($('cmbHiringManager').value == -1) {
			err = true;
			msg += "\t- <?php echo $lang_Recruit_JobVacancy_PleaseSpecifyHiringManager; ?>\n";
        }
		*/
		//alert($('txtTitle').value);
        if ($('txtTitle').value == "" || $('txtTitle').value == null) {
			err = true;
			msg += "\t- <?php echo $lang_News_PleaseSpecifyNewsTitle; ?>\n";
        }

		if (err) {
			alert(msg);
			return false;
		} else {
			return true;
		}
		
		//return true;
	}

    function save() {

		if (validate()) {
        	$('frmJobVacancy').submit();
		} else {
			return false;
		}
    }
	//Chinh nguyen add
	function returnEmpDetail(){
		var popup=window.open('../../templates/hrfunct/emppop.php?reqcode=REP&LEAVE=LEAVE','Employees','height=450,width=400');
        if(!popup.opener) popup.opener=self;
		popup.focus();
	}
	function reset() {
		$('frmJobVacancy').reset();
	}

	/*
	function mout() {
	
		if(editMode) {
			$('editBtn').src='../../themes/<?php echo $styleSheet;?>/pictures/btn_save.gif';
		} else {
			$('editBtn').src='../../themes/<?php echo $styleSheet;?>/pictures/btn_edit.gif';
		}
	}

	function mover() {
		if(editMode) {
			$('editBtn').src='../../themes/<?php echo $styleSheet;?>/pictures/btn_save_02.gif';
		} else {
			$('editBtn').src='../../themes/<?php echo $styleSheet;?>/pictures/btn_edit_02.gif';
		}
	}
	*/
	function mout() {		
			$('editBtn').src='../../themes/<?php echo $styleSheet;?>/pictures/btn_save.gif';
		
	}

	function mover() {		
			$('editBtn').src='../../themes/<?php echo $styleSheet;?>/pictures/btn_save_02.gif';		
	}
	
	function edit()	{

<?php if($locRights['edit']) { ?>
		
		if (editMode) {
			save();
			return;
		}
		save();
		editMode = true;
		var frm = $('frmJobVacancy');
		<?php $edit =true; ?>
		for (var i=0; i < frm.elements.length; i++) {
			frm.elements[i].disabled = false;
		}
		$('editBtn').src="../../themes/<?php echo $styleSheet;?>/pictures/btn_save.gif";
		$('editBtn').title="<?php echo $lang_Common_Save; ?>";

<?php } else {?>
		alert('<?php echo $lang_Common_AccessDenied;?>');
<?php } ?>
	}
	
	function showAutoSuggestTip(obj) {
		if (obj.value == '<?php echo $lang_Common_TypeHereForHints; ?>') {
			obj.value = '';
			obj.style.color = '#000000';
		}
	}

</script>

    <link href="../../themes/<?php echo $styleSheet;?>/css/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">@import url("../../themes/<?php echo $styleSheet;?>/css/style.css"); </style>

    <style type="text/css">
    <!--

	.items {
		border-top: none;
		border-left: solid 1px #999999;
		border-right: solid 1px #999999;
		border-bottom: solid 1px #999999;
		padding: 4px;
		display: none;
		width: 240px;
	}

    label,select,input,textarea {
        display: block;  /* block float the labels to left column, set a width */
        width: 150px;
        float: left;
        margin: 10px 0px 2px 0px; /* set top margin same as form input - textarea etc. elements */
    }
    input[type=checkbox] {
		width: 15px;
		background-color: transparent;
		vertical-align: bottom;
    }

    #active {
        width: 15px;
        height: 15px;
        background-color: transparent;
        vertical-align: bottom;
    }

    /* this is needed because otherwise, hidden fields break the alignment of the other fields */
    input[type=hidden] {
        display: none;
        border: none;
        background-color: red;
    }

    label {
        text-align: left;
        width: 110px;
        padding-left: 10px;
    }

    select,input,textarea {
        margin-left: 10px;
    }

    input,textarea {
        padding-left: 4px;
        padding-right: 4px;
    }

    textarea {
        width: 330px;
        height: 400px;
    }

    form {
        min-width: 550px;
        max-width: 600px;
    }

    br {
        clear: left;
    }

    .roundbox {
        margin-top: 10px;
        margin-left: 0px;
        width: 630px;
        height: 700px;
    }

    .roundbox_content {
        padding-bottom:15px;
    }

	.hidden {
		display: none;
	}

	.display-block {
		display: block;
	}

	#nohiringmanagers {
		font-style: italic;
		color: red;
        padding-left: 10px;
        width: 400px;
        border: 1px;
	}
	
	#employeeSearchAC {
 	    width:15em; /* set width here */
 	    padding-bottom:2em;
 	}
	
 	#employeeSearchAC {
 	    z-index:9000; /* z-index needed on top instance for ie & sf absolute inside relative issue */
 	}
	
 	#txtEmployeeSearch {
 	    _position:absolute; /* abs pos needed for ie quirks */
 	}
    -->
</style>
<?php include ROOT_PATH."/lib/common/autocomplete.php"; ?>

<!-- TinyMCE Chinh Nguyen Add-->
<script language="javascript" type="text/javascript" src="../../scripts/ajaxfilemanager/jscripts/tiny_mce/tiny_mce.js"></script>
	<script language="javascript" type="text/javascript" src="../../scripts/ajaxfilemanager/jscripts/general.js"></script>
	<script language="javascript" type="text/javascript">
		tinyMCE.init({
			mode : "textareas",
			elements : "ajaxfilemanager",
			theme : "advanced",
			//editor_selector : "mceAdvance",
			plugins : "advimage,advlink,media,contextmenu",
			theme_advanced_buttons1_add_before : "newdocument,separator",
			theme_advanced_buttons1_add : "fontselect,fontsizeselect",
			theme_advanced_buttons2_add : "separator,forecolor,backcolor,liststyle",
			theme_advanced_buttons2_add_before: "cut,copy,separator,",
			theme_advanced_buttons3_add_before : "",
			theme_advanced_buttons3_add : "media",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			extended_valid_elements : "hr[class|width|size|noshade]",
			file_browser_callback : "ajaxfilemanager",
			paste_use_dialog : false,
			theme_advanced_resizing : true,
			theme_advanced_resize_horizontal : true,
			apply_source_formatting : true,
			force_br_newlines : true,
			force_p_newlines : false,	
			relative_urls : true
		});

		function ajaxfilemanager(field_name, url, type, win) {
			var ajaxfilemanagerurl = "../../../../jscripts/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php";
			switch (type) {
				case "image":
					break;
				case "media":
					break;
				case "flash": 
					break;
				case "file":
					break;
				default:
					return false;
			}
            tinyMCE.activeEditor.windowManager.open({
                url: "../../../../jscripts/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php",
                width: 782,
                height: 440,
                inline : "yes",
                close_previous : "no"
            },{
                window : win,
                input : field_name
            });
            
/*            return false;			
			var fileBrowserWindow = new Array();
			fileBrowserWindow["file"] = ajaxfilemanagerurl;
			fileBrowserWindow["title"] = "Ajax File Manager";
			fileBrowserWindow["width"] = "782";
			fileBrowserWindow["height"] = "440";
			fileBrowserWindow["close_previous"] = "no";
			tinyMCE.openWindow(fileBrowserWindow, {
			  window : win,
			  input : field_name,
			  resizable : "yes",
			  inline : "yes",
			  editor_id : tinyMCE.getWindowArg("editor_id")
			});
			
			return false;*/
		}
	</script>

<!-- /TinyMCE -->

</head>
<body class="yui-skin-sam">
	
  	<div id="navigation" style="margin:0;text-align: left">
  		<img title="Back" onMouseOut="this.src='../../themes/<?php echo $styleSheet;?>/pictures/btn_back.gif';"
  			 onMouseOver="this.src='../../themes/<?php echo $styleSheet;?>/pictures/btn_back_02.gif';"
  			 src="../../themes/<?php echo $styleSheet;?>/pictures/btn_back.gif" onClick="goBack();">
	</div>
    <?php $message =  isset($_GET['message']) ? $_GET['message'] : null;
    	if (isset($message)) {
			$col_def = CommonFunctions::getCssClassForMessage($message);
			$message = "lang_Common_" . $message;
	?>
	<div class="message">
		<font class="<?php echo $col_def?>" size="-1" face="Verdana, Arial, Helvetica, sans-serif">
			<?php echo (isset($$message)) ? $$message: ""; ?>
		</font>
	</div>
	<?php }	?>
  <div class="roundbox">
  <form name="frmJobVacancy" id="frmJobVacancy" method="post" action="<?php echo $formAction;?>" onSubmit="return false;">
		<input type="hidden" id="txtId" name="txtId" value="<?php echo $records['news_id'];?>"/><br/>
		
		<label for="txtTitle"><span class="error">*</span> <?php echo $lang_News_News_Title; ?></label>
		
		<input type="text" id="txtTitle" name="txtTitle" tabindex="3"      	
        	style="width: 350px; padding-left: 0px" value="<?php echo htmlspecialchars($records['news_title']); ?>"/><br/>
        	<br/>
		<!--
		<label for="txtDesc"><?php echo $lang_Commn_description; ?></label><br/>
		
        <textarea id="txtDesc" name="txtDesc" tabindex="3"
        	<?php echo $disabled;?> class='mceSimple'><?php echo htmlspecialchars($records['news_description']); ?></textarea><br/>
      -->
        <label for="txtDesc"><?php echo $lang_Commn_Content; ?></label><br/>
        
        <textarea id="txtContent" name="txtContent" tabindex="3"
        	class='mceSimple'><?php echo htmlspecialchars($records['news_content']); ?></textarea><br/>
		
		<label for="txtType"><?php echo $lang_Commn_News_Type; ?></label>
			
		<select name="txtType" id="txtType" style="width:100px;margin:5px 0 5px 0;">
		<?php
			$tempValue=0;
			$temp =  $records['news_type'];
			 if($temp=="News"){
			 	$tempValue=1;
			 }
			 if($temp=="Event"){
			 	$tempValue=2;
			 }
			 if($temp=="Announcement"){
			 	$tempValue=3;
			 }
		 ?>
		<option value="<?php echo $tempValue ?>"><?php echo $records['news_type']; ?></option>
		<?php
			if($tempValue==1){	?>
			<option value="2">Event</option>
			 <option value="3">Announcement</option>
			 
		<?php	}elseif($tempValue==2){	?>
			<option value="1">News</option>
			 <option value="3">Announcement</option>
		<?php	}else{	?>
			<option value="1">News</option>
			 <option value="2">Event</option>
		<?php	}?>
		</select> 
		<br/><br/>
        <div align="left">
            <img onClick="edit();" id="editBtn"
            	onMouseOut="mout();" onMouseOver="mover();"
            	src="../../themes/<?php echo $styleSheet;?>/pictures/<?php echo $new ? 'btn_save.gif' : 'btn_save.gif';?>">
			<img id="saveBtn" src="../../themes/<?php echo $styleSheet;?>/pictures/btn_clear.gif"
			onMouseOut="this.src='../../themes/<?php echo $styleSheet;?>/pictures/btn_clear.gif';"
			onMouseOver="this.src='../../themes/<?php echo $styleSheet;?>/pictures/btn_clear_02.gif';" onClick="reset();" >
        </div>
	</form>
    </div>
    <div id="navigation" style="margin:0;text-align: right">
  		<img title="Back" onMouseOut="this.src='../../themes/<?php echo $styleSheet;?>/pictures/btn_back.gif';"
  			 onMouseOver="this.src='../../themes/<?php echo $styleSheet;?>/pictures/btn_back_02.gif';"
  			 src="../../themes/<?php echo $styleSheet;?>/pictures/btn_back.gif" onClick="goBack();">
	</div>

    <div id="notice"><?php echo preg_replace('/#star/', '<span class="error">*</span>', $lang_Commn_RequiredFieldMark); ?>.</div>
	<script type="text/javascript">
        <!--
        	if (document.getElementById && document.createElement) {
   	 			initOctopus();
			}

		<?php 
			$i = 0; 
			
			//foreach ($employeeSearchList as $record) {
		?>
			//employeeSearchList[<?php echo $i++; ?>] = new Array('<?php //echo implode("', '", $record); ?>');
		<?php 
			//}
		?>


 	 	YAHOO.OrangeHRM.autocomplete.ACJSArray = new function() {
				
			// Instantiate second JS Array DataSource 
		    this.oACDS = new YAHOO.widget.DS_JSArray(employeeSearchList); 
		 
		    // Instantiate second AutoComplete 
		    this.oAutoComp = new YAHOO.widget.AutoComplete('txtHiringManagerSearch','employeeSearchACContainer', this.oACDS); 
		    this.oAutoComp.prehighlightClassName = "yui-ac-prehighlight"; 
		    this.oAutoComp.typeAhead = false; 
		    this.oAutoComp.useShadow = true; 
		    this.oAutoComp.forceSelection = true; 
		    this.oAutoComp.formatResult = function(oResultItem, sQuery) { 
		        var sMarkup = oResultItem[0] + "<br />" + oResultItem[1] .fontsize(-1).fontcolor('#999999')  + "&nbsp;";
		        return (sMarkup);
		    };
		    
 	 	};
 	 	-->
 	 </script>
</body>
</html>
